package com.dream.tihai.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dream.tihai.entity.ProblemEntity;
import com.dream.tihai.mapper.ProblemMapper;
import com.dream.tihai.service.IProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @author Valley
 * Created by Valley on 2022/12/14
 */
@Service
public class ProblemServiceImpl implements IProblemService {

    @Autowired
    ProblemMapper problemMapper;


    @Override
    public List<ProblemEntity> selectProblemList(ProblemEntity problem) {
        LambdaQueryWrapper<ProblemEntity> wrapper = new LambdaQueryWrapper<>();
        if (problem.getTypeId() != 0){
            wrapper.eq(ProblemEntity::getTypeId, problem.getTypeId());
        }
        if (!StrUtil.isBlankIfStr(problem.getTitle())){
            wrapper.like(ProblemEntity::getTitle, problem.getTitle());
        }

        List<ProblemEntity> entityList = problemMapper.selectList(wrapper);
        return entityList;
    }

    @Override
    public boolean submitProblem(ProblemEntity problem) {

        int insert = problemMapper.insert(problem);
        if (insert != 0){
            return true;
        }

        return false;
    }
}
